﻿
Namespace LightSwitchApplication

    Public Class ConsultPreNatal

        Private myDialogNewPregnancy As ModalWindow
        Private myCurrentPregnancyVisitModal As ModalWindow
        Private myPreviousPregnancyModal As ModalWindow

        Private Sub ConsultPreNatal_InitializeDataWorkspace(saveChangesTo As System.Collections.Generic.List(Of Microsoft.LightSwitch.IDataService))
            ' Write your code here.
            myDialogNewPregnancy = New ModalWindow(Me.Pregnancies, "StartPregnancyPopup")
            myCurrentPregnancyVisitModal = New ModalWindow(Me.CurrentPregnancyVisits, "CurrentPregnancyVisitPopup")
            myPreviousPregnancyModal = New ModalWindow(Me.PreviousPregnancies, "PreviousPregnancyPopup")

            setPregnancyButtons()

            If Not patientNo = Nothing Then
                Me.PatientProperty = Me.Patient
                Me.DisplayName = "PreNatal - " & Me.Patient.SummaryName
            Else
                Me.PatientProperty = New Patient()
            End If

            If Me.PatientProperty.Patient_More Is Nothing Then
                Me.PatientProperty.Patient_More = New Patient_More
            End If

            If Me.Patient.photo Is Nothing Then
                Me.FindControl("Patient_photo").IsVisible = False
            End If

        End Sub

        Private Sub ConsultPreNatal_Saved()
            ' Write your code here.
            'Me.Close(False)
            'Application.Current.ShowDefaultScreen(Me.PatientProperty)
        End Sub

        Private Sub PreviousPregnancies_SelectionChanged()
            If Not Me.PreviousPregnancies.SelectedItem Is Nothing Then
                Me.FindControl("PreviousPregnancyVisits").DisplayName = "PreNatal visits for delivery date " & Me.PreviousPregnancies.SelectedItem.DeliveryDate
            End If
        End Sub

        Private Sub StartPregnancyMethod_Execute()
            ' Write your code here.
            myDialogNewPregnancy.AddEntity()
        End Sub

        Private Sub ConsultPreNatal_Created()
            ' Write your code here.
            myDialogNewPregnancy.Initialise()
            myCurrentPregnancyVisitModal.Initialise()
            myPreviousPregnancyModal.Initialise()
        End Sub

        Private Sub OkModalNewPregnancyMethod_Execute()
            ' Write your code here.
            myDialogNewPregnancy.DialogOk()
            setPregnancyButtons()
        End Sub

        Private Sub CancelModalNewPregnancyMethod_Execute()
            ' Write your code here.
            myDialogNewPregnancy.DialogCancel()
        End Sub


#Region " - Common  Methods - "
        Private Sub setPregnancyButtons()
            If Me.Pregnancies.SelectedItem IsNot Nothing Then
                Me.FindControl("StartPregnancyMethod").IsEnabled = False
                Me.FindControl("ConcludePregnancyMethod").IsEnabled = True
            Else
                Me.FindControl("StartPregnancyMethod").IsEnabled = True
                Me.FindControl("ConcludePregnancyMethod").IsEnabled = False
            End If
        End Sub
#End Region

#Region " - Current Pregnancy Visit Methods - "
        Private Sub CurrentPregnancyVisitsAddAndEditNew_CanExecute(ByRef result As Boolean)
            ' Write your code here.
            result = myCurrentPregnancyVisitModal.CanAdd
        End Sub

        Private Sub CurrentPregnancyVisitsAddAndEditNew_Execute()
            ' Write your code here.
            myCurrentPregnancyVisitModal.AddEntity()
            With CurrentPregnancyVisits.SelectedItem
                .Weeks = Pregnancies.SelectedItem.WeeksNow
                .VisitDate = Now
            End With
        End Sub

        Private Sub OkCurrentPregnancyVisitMethod_Execute()
            ' Write your code here.
            myCurrentPregnancyVisitModal.DialogOk()
        End Sub

        Private Sub CancelCurrentPregnancyMethod_Execute()
            ' Write your code here.
            myCurrentPregnancyVisitModal.DialogCancel()
        End Sub
#End Region ' - Current Pregnancy Visit Methods - 
        
        
#Region " - Conclude Current Pregnancy Visit Methods - "
        Private Sub ConcludePregnancyMethod_Execute()
            ' Write your code here.
            myPreviousPregnancyModal.AddEntity()
            Me.PreviousPregnancies.SelectedItem.PregnancyNo = Pregnancies.SelectedItem.pregnancyno
        End Sub

        Private Sub OkAddtoPreviousPregnancy_Execute()
            ' Write your code here.
            myPreviousPregnancyModal.DialogOk()
        End Sub

        Private Sub CancelAddtoPreviousPregnancy_Execute()
            ' Write your code here.
            myPreviousPregnancyModal.DialogCancel()
        End Sub
#End Region ' - Conclude Current Pregnancy Visit Methods - 
    End Class
End Namespace